package br.urca.impl;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.BiIdiomasDAO;
import br.urca.model.BiIdiomas;

@Transactional
public class JPABiIdiomasDAO implements BiIdiomasDAO {
	
	private EntityManager manager;
	
	public JPABiIdiomasDAO() {
		this(null);
	}
	
	@Inject
	public JPABiIdiomasDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public BiIdiomas getPorId(Short codIdioma) {
		try {
			return this.manager
					.createQuery(
							"SELECT b FROM BiIdiomas b "
									+ " WHERE b.codIdioma = :codigo",
							BiIdiomas.class).setParameter("codigo", codIdioma)
					.getSingleResult();
		} catch (Exception e) {
			return null;
		}
	}

}
